<!--
 * @Author: your name
 * @Date: 2022-03-29 10:25:35
 * @LastEditTime: 2022-03-29 11:48:36
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\3.29.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var characterReplacement = function (s, k) {
            let charArr = Array(26).fill(0);
            let n = s.length, maxChari = 0;
            let result = 0;
            let step = 'A'.charCodeAt();
            for (let left = 0, right = 0, sum = 0; right < n; right++) {
                charArr[s[right].charCodeAt() - step]++;
                maxChari = charArr[maxChari] >= charArr[s[right].charCodeAt() - step] ? maxChari : s[right].charCodeAt() - step;
                sum += s[right].charCodeAt() !== (maxChari + step) ? 1 : 0;
                while (sum > k) {
                    charArr[s[left].charCodeAt() - step]--;
                    sum -= s[left++].charCodeAt() !== (maxChari + step) ? 1 : 0;
                }
                result = Math.max(result, right - left + 1);
            }
            return result;
        };
        console.log(characterReplacement("BAAA", 0));
        console.log('A'.charCodeAt());
    </script>
</body>

</html>